/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef IMAGE_UTILS_H_
#define IMAGE_UTILS_H_
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#ifdef __cplusplus
extern "C" {
#endif

inline void
move_420_block(int yTL, int yTR, int yBL, int yBR, int u, int v, 
	       int rowPixels, unsigned char * rgb, int bits);

/* Converts from planar YUV420 to RGB24. */
void 
yuv420p_to_rgb(int width, int height,
	       unsigned char *pIn0, unsigned char *pOut0, int bits);


/**
* Saves PGM image (gray scale image)
*/
void imageutils_pgm_save(unsigned char* im,char* filename,int width,int height);

/**
* PPM save. Saves PPM image (RGB)
*/
void imageutils_ppm_save(unsigned char* im,char* filename,int width,int height);

/**
* Load PPM image
*/
void imageutils_ppm_load(unsigned char* im,char* filename,int *width,int *height);


int yuv422torgb (char *YUV, char *RGB, int NumPixels);
int yuv422toyuv420p (char *YUV, char *YUV2, int M, int N);

/**
 * Flips RGB image - be careful that you have proper parameters and actually RGB image
 * @param img The image data
 * @param width The width of the image in pixels (one pixel has R,G and B value)
 * @param height The height of the image in pixels
 */
void imageutils_flip_rgbimage( unsigned char *img, unsigned int width, unsigned int height);

/**
* Undistort RGB image - be careful that you have proper parameters and actually RGB image
* @param warped The undistorted image data
* @param img The image data
* @param k1 The undistortion parameter
* @param k2 The undistortion parameter
* @param u0 The undistortion center x-coordinate
* @param v0 The undistortion center y-coordinate
* @param M The width of the image in pixels (one pixel has R,G and B value)
* @param N The height of the image in pixels
*/
void undist_rgb_image(unsigned char *warped, unsigned char *imA, double k1, double k2,double u0, double v0, int M, int N);

#ifdef __cplusplus
}
#endif

	       
#endif
